UI.Form._startupForms = []

UI.Form.prototype._loadControls = function(defn) {
	var ctls = defn.controls
	this.allControls = []
	if (ctls != null) {
		for (var idx = 0; idx < ctls.length; idx++) {
			var ctl = ctls[idx];
			var factory = UI.Form._controlFactories[ctl.type];
			if (factory != null) {
				var instance = new factory(this, this, ctl)
				this[ctl.name] = instance
				this.allControls.push(instance)
				instance.form = this
			}
		}
	}
}

UI.Form.prototype.showSheet = function(sheet) {
	if (!sheet._isLoaded) {
		sheet._isLoaded = true
		sheet._load()
	}
	this._showSheet(sheet)
}

UI.Form.prototype._load = function() {
	if (this.config.Load != null)
		this.config.Load.call(this);
	var ctls = this.allControls;
	for (var idx = 0; idx < ctls.length; idx++) {
		var ctl = ctls[idx]
		if (ctl._load != null)
			ctl._load();
		}
}

UI.DefineWindow = function(defn) {
	var constructor = function(arg) {
		this._createWindow(defn)
		this._loadControls(defn)
		this.createParam = arg
		this._load()
	}
	constructor.prototype = new UI.Form()
	UI.Form._startupForms.push(constructor)
	return constructor;
}

UI.DefineSheet = function(defn) {
	var constructor = function(arg) {
		this._createSheet(defn)
		this._loadControls(defn)
		this.createParam = arg
		this._load()
	}
	constructor.prototype = new UI.Form()
	UI.Form._startupForms.push(constructor)
	return constructor;
}

UI.DefinePanel = function(defn) {
	var constructor = function(arg) {
		this._createPanel(defn)
		this._loadControls(defn)
		this.createParam = arg
		this._load()
	}
	constructor.prototype = new UI.Form()
	UI.Form._startupForms.push(constructor)
	return constructor;
}
